/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import java.sql.*;

/**
 *
 * @author Max
 */
public class UtilBean {
    private String login;
    private static final String url = "jdbc:derby://localhost:1527/sample";
    private static final String user = "app";
    private static final String pwd = "app";
    
    public UtilBean(){
        login = "Sconosciuto";
    }
    
    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }
    
    public String getStatoPiste(){
        String out = "";
        try{
            DriverManager.registerDriver(new org.apache.derby.jdbc.ClientDriver());
            Connection c = DriverManager.getConnection(url, user, pwd);
            Statement st = c.createStatement();
            ResultSet rs = st.executeQuery("SELECT NOME, STATO, DIFFICOLTA, COMPRENSORIO FROM PISTA ORDER BY COMPRENSORIO");
            String comp = "";
            while(rs.next()){
                String comp2 = rs.getString("COMPRENSORIO");
                if(!comp.equals(comp2)){
                    out = out + "<div class='comprensorio'>" + comp2 + "</div>";
                    comp = comp2;               
                }
                String stato = "images/rosso.jpg";
                String colore = rs.getString("DIFFICOLTA");
                if((rs.getString("STATO")).equals("1")) stato = "images/verde.jpg";
                out = out + "<div class='piste'><div class='"+colore+"'>" + rs.getString("NOME") + "</div><img class='aperto_chiuso' src='"+stato+"' width='10' height='10'>"  + "</div>";
            }
            rs.close(); st.close(); c.close();
        }catch (SQLException e) {out = e.getMessage();}
        return out;
    }
    
    public String getEventi(){
        String out = "";
        try{
            DriverManager.registerDriver(new org.apache.derby.jdbc.ClientDriver());
            Connection c = DriverManager.getConnection(url, user, pwd);
            Statement st = c.createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM EVENTO ORDER BY DATA_PUBBLICAZIONE");
            
            while(rs.next()){
                String descr = rs.getString("DESCRIZIONE");
                if(descr.length()>=100) descr = descr.substring(0, 100);
                out = out + "<div class='post_evento'><img src='images/img06.jpg' alt='' width='100' height='50' class='left' />";
                out = out + "<div>" + rs.getString("DATA_EVENTO") + "</div><div class='titolo_post'>" + rs.getString("TITOLO") + "</div><div>" + descr + "</div></div>";
                out = out + "<p class='meta'>Postato il " + rs.getString("DATA_PUBBLICAZIONE") + "</p>";
            }
            rs.close(); st.close(); c.close();
        }catch (SQLException e) {out = e.getMessage();}
        return out;
    }
    
    public String getTagliaMaglia() {
        String out = "";
        out = "<select name=\"tagliaMaglia\">\n";
        out = out + "<option value=- selected>-</option>\n";
        out = out + "<option value=XXXS>XXXS</option>\n";
        out = out + "<option value=XXS>XXS</option>\n";
        out = out + "<option value=XS>XS</option>\n";
        out = out + "<option value=S>S</option>\n";
        out = out + "<option value=M>M</option>\n";
        out = out + "<option value=L>L</option>\n";
        out = out + "<option value=XL>XL</option>\n";
        out = out + "<option value=XXL>XXL</option>\n";
        out = out + "<option value=XXXL>XXXL</option>\n";
        out = out + "</select>\n";

        return out;
    }
    
    public String getData() {
        String out = "";
        out = "<select name=\"giorno\">\n";
        for (int i = 1; i <= 31; i++) {
            if(i==1)
                out = out + "\n<option value=" + i + " selected>" + i + "</option>\n";
            out = out + "\n<option value=" + i + ">" + i + "</option>\n";
        }
        out = out + "</select>\n";

        out = out + "<select name=\"mese\">\n";
        for (int i = 1; i <= 12; i++) {
            if(i==1)
                out = out + "\n<option value=" + i + " selected>" + i + "</option>\n";
            out = out + "\n<option value=" + i + ">" + i + "</option>\n";
        }
        out = out + "</select>\n";

        out = out + "<select name=\"anno\">\n";
        for (int i = 1940; i <= 1993; i++) {
            if(i==1)
                out = out + "\n<option value=" + i + " selected>" + i + "</option>\n";
            out = out + "\n<option value=" + i + ">" + i + "</option>\n";
        }
        out = out + "</select>\n";

        return out;
    }
}